<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><script>(()=>{const e=navigator.serviceWorker;e?e.register("/sw.js").then((async e=>{console.log("SWPP 注册成功");try{await e.periodicSync.register("update",{minInterval:864e5})}catch(e){console.log("Periodic Sync 注册失败",e)}})).catch((e=>console.error("SWPP 注册失败",e))):console.warn("当前浏览器不支持 SW")})()</script><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>Hexo配置SWPP实现PWA | LiuShen's Blog</title><meta name="author" content="LiuShen"><meta name="copyright" content="LiuShen"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="robots" content="index, follow"><meta name="description" content="前几天，我调整了网站样式，但受浏览器缓存机制影响，更新后无法立即生效，需要手动刷新。为优化体验，我向空梦大佬请教了SWPP配置，最终实现了自动更新样式，并成功部署了PWA，在此分享给大家。"><meta property="og:type" content="article"><meta property="og:title" content="Hexo配置SWPP实现PWA"><meta property="og:url" content="https://blog.liushen.fun/posts/4355f2b3/"><meta property="og:site_name" content="LiuShen's Blog"><meta property="og:description" content="前几天，我调整了网站样式，但受浏览器缓存机制影响，更新后无法立即生效，需要手动刷新。为优化体验，我向空梦大佬请教了SWPP配置，最终实现了自动更新样式，并成功部署了PWA，在此分享给大家。"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://p.liiiu.cn/i/2025/03/27/67e56a745e1cc.webp"><meta property="article:published_time" content="2025-03-28T06:53:00.000Z"><meta property="article:modified_time" content="2025-03-28T06:55:00.000Z"><meta property="article:author" content="LiuShen"><meta property="article:tag" content="优化"><meta property="article:tag" content="SWPP"><meta property="article:tag" content="博客管理"><meta property="article:tag" content="Service Worker"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://p.liiiu.cn/i/2025/03/27/67e56a745e1cc.webp"><link rel="shortcut icon" href="/favicon.ico"><link rel="canonical" href="https://blog.liushen.fun/posts/4355f2b3/"><link rel="preconnect" href="https://jsd.liiiu.cn"><meta name="baidu-site-verification" content="codeva-i2bF9bXDJs"><meta name="sogou_site_verification" content="1rIjtK6RhE"><meta name="360-site-verification" content="b9a9f96ae38a1932a326f8ba255cc74b"><meta name="msvalidate.01" content="F7C246820EB04DD140494C98F93A97C7"><meta name="google-site-verification" content="VH3ZE6m42MZDqpTY2tD-XoxDt9iUj2HoiC3W2neB7F4"><link rel="manifest" href="/manifest.json"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/config/img/pwa/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/config/img/pwa/favicon-16x16.png"><link rel="mask-icon" href="/config/img/pwa/favicon-mask.svg" color="#5bbad5"><link rel="stylesheet" href="/css/index.css?v=5.0.0"><link rel="stylesheet" href="/css/custom.css?v=5.0.0"><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/@fortawesome/fontawesome-free@6.7.2/css/all.min.css"><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/@fancyapps/ui@5.0.36/dist/fancybox/fancybox.min.css" media="print" onload='this.media="all"'><script>(()=>{const e={set:(e,t,o)=>{if(!o)return;const n=Date.now()+864e5*o;localStorage.setItem(e,JSON.stringify({value:t,expiry:n}))},get:e=>{const t=localStorage.getItem(e);if(!t)return;const{value:o,expiry:n}=JSON.parse(t);if(!(Date.now()>n))return o;localStorage.removeItem(e)}};window.btf={saveToLocal:e,getScript:(e,t={})=>new Promise(((o,n)=>{const a=document.createElement("script");a.src=e,a.async=!0,Object.entries(t).forEach((([e,t])=>a.setAttribute(e,t))),a.onload=a.onreadystatechange=()=>{a.readyState&&!/loaded|complete/.test(a.readyState)||o()},a.onerror=n,document.head.appendChild(a)})),getCSS:(e,t)=>new Promise(((o,n)=>{const a=document.createElement("link");a.rel="stylesheet",a.href=e,t&&(a.id=t),a.onload=a.onreadystatechange=()=>{a.readyState&&!/loaded|complete/.test(a.readyState)||o()},a.onerror=n,document.head.appendChild(a)})),addGlobalFn:(e,t,o=!1,n=window)=>{const a=n.globalFn||{};a[e]=a[e]||{},o&&a[e][o]||(a[e][o||Object.keys(a[e]).length]=t,n.globalFn=a)}};const t=()=>{document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},o=()=>{document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};btf.activateDarkMode=t,btf.activateLightMode=o;const n=e.get("theme"),a=(new Date).getHours();void 0===n?a<=6||a>=18?t():o():"light"===n?o():t();const r=e.get("aside-status");void 0!==r&&document.documentElement.classList.toggle("hide-aside","hide"===r);/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})()</script><script>const GLOBAL_CONFIG={root:"/",algolia:{appId:"7IX3UBC6JW",apiKey:"4ac2846352e499675081f1277fb961c1",indexName:"My Blog",hitsPerPage:6,languages:{input_placeholder:"搜索全站文章",hits_empty:"未找到符合您查询的内容：${query}",hits_stats:"找到 ${hits} 条结果，耗时 ${time} 毫秒"}},localSearch:void 0,translate:{defaultEncoding:2,translateDelay:0,msgToTraditionalChinese:"繁",msgToSimplifiedChinese:"簡"},noticeOutdate:{limitDay:365,position:"top",messagePrev:"本篇文章从发布到现在已经隔了",messageNext:"天了，里面的内容可能过期了，你要自己甄别一下哟👉👈"},highlight:{plugin:"highlight.js",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:400,highlightFullpage:!1,highlightMacStyle:!0},copy:{success:"😋复制啦！请注意版权信息呀！",error:"😪呜呜，复制失败了！",noSupport:"🤐浏览器不支持呢，你用的啥玩意？"},relativeDate:{homepage:!1,post:!1},runtime:"天",dateSuffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:1e3,languages:{author:"作者: LiuShen",link:"链接: ",source:"来源: LiuShen's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"已切换为繁体中文",cht_to_chs:"已切换为简体中文",day_to_night:"已切换为深色模式",night_to_day:"已切换为浅色模式",bgLight:"rgba(255, 255, 255, 0.509)",bgDark:"rgba(48, 48, 48, 0.509)",position:"top-right"},infinitegrid:{js:"https://jsd.liiiu.cn/npm/@egjs/infinitegrid@4.12.0/dist/infinitegrid.min.js",buttonText:"加载更多"},isPhotoFigcaption:!0,islazyload:!0,isAnchor:!1,percent:{toc:!0,rightside:!1},autoDarkmode:!1}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"Hexo配置SWPP实现PWA",isPost:!0,isHome:!1,isHighlightShrink:void 0,isToc:!0,postUpdate:"2025-03-28 14:55:00"}</script><link rel="stylesheet" href="https://jsd.liiiu.cn/gh/willow-god/Sharding-fonts/Yozai-Medium/result.min.css"><link rel="stylesheet" href="/config/memos/memos.css"><script defer src="/sw-dom.js"></script><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/swiper@11.1.14/swiper-bundle.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="/config/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 7.3.0"><link rel="alternate" href="/atom.xml" title="LiuShen's Blog" type="application/atom+xml"></head><body><div class="float-box right top"></div><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><img class="load-image" src="" data-lazy-src="/config/img/preloader.gif" alt=""></div><script async>(()=>{const e=document.getElementById("loading-box"),d=document.body,t=()=>{d.style.overflow="",e.classList.add("loaded")},n=()=>{d.style.overflow="hidden",e.classList.remove("loaded")};n();let o=!1;window.addEventListener("load",(()=>{o||(t(),o=!0)})),setTimeout((()=>{o||(t(),o=!0)}),5e3),window.addEventListener("load",(()=>{t()})),setTimeout((function(){t()}),3e3),document.getElementById("loading-box").addEventListener("click",(()=>{t()})),document.addEventListener("pjax:send",(()=>{n()})),document.addEventListener("pjax:complete",(()=>{t()}))})()</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="add-menu-container"><div id="travellings"><a class="site-page" href="https://www.travellings.cn/go.html" title="友链接力-随机开往" target="_blank" rel="noopener nofollow"><i class="fa-solid fa-bus fa-fw"></i></a></div><div id="ten-years"><a class="site-page" href="https://foreverblog.cn/go.html" title="友链接力-十年之约" target="_blank" rel="noopener nofollow"><i class="fa-brands fa-nfc-symbol fa-fw"></i></a></div></div><div class="is-center" id="sidebar-avatar"><div class="avatar-img is-center"><img class="mood-icon" src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/14/67d301461a24a.webp" alt="🤤" onerror='this.onerror=null,this.src="/img/friend_404.gif"'><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/13/67d2fc82d329c.webp" onerror='this.onerror=null,this.src="/img/friend_404.gif"' alt="avatar"></div><div class="author-info__name">LiuShen</div></div><div class="site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">72</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">98</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/willow-god"><i class="fab fa-github"></i><span>Follow Me 🛫</span></a><div class="menus_items visible"><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fas fa-home"></i> <span>导航</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.liushen.fun/"><i class="fa-fw fa-solid fa-house-flag"></i> <span>个人主页</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://xc.liushen.fun/"><i class="fa-fw fa fa-camera-retro"></i> <span>个人相册</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-graduation-cap"></i> <span>整理</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>时光卷轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i> <span>文章标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i> <span>文章分类</span></a></li><li><a class="site-page child" href="/charts/"><i class="fa-fw fa-solid fa-chart-pie"></i> <span>文章通览</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-user-group"></i> <span>友人</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链展示</span></a></li><li><a class="site-page child" href="/addlink/"><i class="fa-fw fa fa-at"></i> <span>友链申请</span></a></li><li><a class="site-page child" href="/fcircle/"><i class="fa-fw fa-solid fa-circle-nodes"></i> <span>朋友动态</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-paper-plane"></i> <span>留言</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa-solid fa-chalkboard"></i> <span>留言白板</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://mm.liushen.fun/"><i class="fa-fw fa-solid fa-pen-nib"></i> <span>提笔摘星</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-stethoscope"></i> <span>分享</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gist.liushen.fun/"><i class="fa-fw fa-solid fa-code"></i> <span>代码片段</span></a></li><li><a class="site-page child" href="/subscribe/"><i class="fa-fw fa-solid fa-rss"></i> <span>订阅本站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://pan.liushen.fun/"><i class="fa-fw fa-solid fa-laptop-file"></i> <span>清羽云盘</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-list"></i> <span>关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/about/"><i class="fa-fw fa fa-address-card"></i> <span>站长资料</span></a></li><li><a class="site-page child" href="/shuoshuo/"><i class="fa-fw fa fa-commenting"></i> <span>日常说说</span></a></li><li><a class="site-page child" href="/devices/"><i class="fa-fw fa-solid fa-tachograph-digital"></i> <span>我的设备</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image:url(https://p.liiiu.cn/i/2025/03/27/67e56a745e1cc.webp)"><nav id="nav"><div class="more-app-btn"><i class="fa-solid fa-fingerprint fa-fw"></i><div class="more-app-list-groups"><div class="more-app-list-groups-container"><div class="more-app-list-group"><div class="more-app-list-title">🦄常用网站</div><div class="more-app-list"><a class="more-app-list-item" href="https://www.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-house"></i><span class="more-app-item-text">个人主页</span></a><a class="more-app-list-item" href="https://blog.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-blog"></i><span class="more-app-item-text">个人博客</span></a><a class="more-app-list-item" href="https://xc.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-image"></i><span class="more-app-item-text">个人相册</span></a><a class="more-app-list-item" href="https://github.com/willow-god" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-brands fa-github"></i><span class="more-app-item-text">Github</span></a></div></div><div class="more-app-list-group"><div class="more-app-list-title">😎周边站点</div><div class="more-app-list"><a class="more-app-list-item" href="https://gist.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-code"></i><span class="more-app-item-text">代码片段</span></a><a class="more-app-list-item" href="https://mm.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-pen-nib"></i><span class="more-app-item-text">提笔摘星</span></a><a class="more-app-list-item" href="https://pan.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-cloud"></i><span class="more-app-item-text">清羽云盘</span></a><a class="more-app-list-item" href="https://um.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-people-group"></i><span class="more-app-item-text">访客统计</span></a><a class="more-app-list-item" href="https://img.liiiu.cn/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-images"></i><span class="more-app-item-text">清羽图床</span></a><a class="more-app-list-item" href="https://chat.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-robot"></i><span class="more-app-item-text">清羽AI</span></a><a class="more-app-list-item" href="https://bsz.liiiu.cn/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-chart-pie"></i><span class="more-app-item-text">不蒜计数</span></a><a class="more-app-list-item" href="https://status.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-server"></i><span class="more-app-item-text">服务检测</span></a></div></div><div class="more-app-list-group"><div class="more-app-list-title">🚁实用工具</div><div class="more-app-list"><a class="more-app-list-item" href="https://tmail.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-envelope"></i><span class="more-app-item-text">临时邮箱</span></a><a class="more-app-list-item" href="https://hot.liushen.fun/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-fire"></i><span class="more-app-item-text">每日热榜</span></a><a class="more-app-list-item" href="https://cover.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-eye"></i><span class="more-app-item-text">封面设计</span></a><a class="more-app-list-item" href="https://mini-cover.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-image"></i><span class="more-app-item-text">迷你封面</span></a><a class="more-app-list-item" href="https://icon.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-icons"></i><span class="more-app-item-text">万能图标</span></a><a class="more-app-list-item" href="https://draw.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-paintbrush"></i><span class="more-app-item-text">灵感白板</span></a><a class="more-app-list-item" href="https://mindmap.qyliu.top/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-network-wired"></i><span class="more-app-item-text">思维导图</span></a><a class="more-app-list-item" href="https://share.liushen.fun/#/" rel="nofollow noopener" target="_blank"><i class="more-app-item-icon fa-solid fa-share-nodes"></i><span class="more-app-item-text">内容中转</span></a></div></div></div></div></div><span id="blog-info"><a class="nav-site-title" href="/" title="LiuShen's Blog"><span class="site-name">LiuShen</span></a></span><div id="menus"></div><div class="menus_items visible"><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fas fa-home"></i> <span>导航</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.liushen.fun/"><i class="fa-fw fa-solid fa-house-flag"></i> <span>个人主页</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://xc.liushen.fun/"><i class="fa-fw fa fa-camera-retro"></i> <span>个人相册</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-graduation-cap"></i> <span>整理</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i> <span>时光卷轴</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i> <span>文章标签</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i> <span>文章分类</span></a></li><li><a class="site-page child" href="/charts/"><i class="fa-fw fa-solid fa-chart-pie"></i> <span>文章通览</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-user-group"></i> <span>友人</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/link/"><i class="fa-fw fas fa-link"></i> <span>友链展示</span></a></li><li><a class="site-page child" href="/addlink/"><i class="fa-fw fa fa-at"></i> <span>友链申请</span></a></li><li><a class="site-page child" href="/fcircle/"><i class="fa-fw fa-solid fa-circle-nodes"></i> <span>朋友动态</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-paper-plane"></i> <span>留言</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa-solid fa-chalkboard"></i> <span>留言白板</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://mm.liushen.fun/"><i class="fa-fw fa-solid fa-pen-nib"></i> <span>提笔摘星</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa-solid fa-stethoscope"></i> <span>分享</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="https://gist.liushen.fun/"><i class="fa-fw fa-solid fa-code"></i> <span>代码片段</span></a></li><li><a class="site-page child" href="/subscribe/"><i class="fa-fw fa-solid fa-rss"></i> <span>订阅本站</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://pan.liushen.fun/"><i class="fa-fw fa-solid fa-laptop-file"></i> <span>清羽云盘</span></a></li></ul></div><div class="menus_item"><span class="site-page group hide"><i class="fa-fw fa fa-list"></i> <span>关于</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/about/"><i class="fa-fw fa fa-address-card"></i> <span>站长资料</span></a></li><li><a class="site-page child" href="/shuoshuo/"><i class="fa-fw fa fa-commenting"></i> <span>日常说说</span></a></li><li><a class="site-page child" href="/devices/"><i class="fa-fw fa-solid fa-tachograph-digital"></i> <span>我的设备</span></a></li></ul></div></div><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center><div id="nav-right"><div id="travellings"><a class="site-page" href="https://www.travellings.cn/go.html" title="友链接力-随机开往" target="_blank" rel="noopener nofollow"><i class="fa-solid fa-bus fa-fw"></i></a></div><div id="ten-years"><a class="site-page" href="https://foreverblog.cn/go.html" title="友链接力-十年之约" target="_blank" rel="noopener nofollow"><i class="fa-brands fa-nfc-symbol fa-fw"></i></a></div><div id="random"><a class="site-page" href="javascript:randomPost()" title="随机前往一个文章"><i class="fa-solid fa-shuffle fa-fw"></i></a></div><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i></span></div><div id="toggle-menu"><span class="site-page" href="javascript:void(0);" title="展开菜单"><i class="fas fa-indent fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Hexo配置SWPP实现PWA</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2025-03-28T06:53:00.000Z" title="发表于 2025-03-28 14:53:00">2025-03-28</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-03-28T06:55:00.000Z" title="更新于 2025-03-28 14:55:00">2025-03-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/website/">博客管理</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">总字数:</span><span class="word-count">6.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>22分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/posts/4355f2b3/#post-comment"><span id="ArtalkCount"><i class="fa-solid fa-spinner fa-spin"></i></span></a></span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s58 18 88 18 58-18 88-18 58 18 88 18v44h-352Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><div class="ai-summary"><div class="ai-head"><div class="ai-head-left"><div class="ai-circle ai-circle-1"></div><div class="ai-circle ai-circle-2"></div><div class="ai-circle ai-circle-3"></div></div><div class="ai-head-right"><a class="ai-about-ai" href="/posts/40702a0d/">关于AI</a></div></div><div class="ai-explanation" style="display:block" data-summary="这里是清羽AI，这篇文章介绍了如何在Hexo博客中配置SWPP（Service Worker Plus Plus）以实现更精细的资源缓存和更新控制。文章首先指出传统Service Worker（SW）的缓存问题，即用户在修改网站样式后需要手动强制刷新缓存（Ctrl+F5），导致用户体验不佳。接着，文章介绍了SWPP的优势，如增量更新、URL竞速、备用URL等特性，这些功能使得网站能够更高效地利用缓存，减少不必要的网络请求，提升用户体验。文章详细讲解了SWPP的配置过程，包括插件安装、Hexo配置文件设置以及SWPP配置文件的编写，特别强调了`track_link`、`isStable`、`referer`、`getStandbyRequests`和`matchCacheRule`等关键配置项的作用和设置方法。最后，文章提醒读者在配置时要小心谨慎，以免影响部分用户的访问体验。">清羽AI正在绞尽脑汁想思路ING···</div><div class="ai-title"><div class="ai-title-left"><i class="fa-brands fa-slack"></i><div class="ai-title-text">清羽のAI摘要</div></div><div class="ai-tag" id="ai-tag">GLM-4-Flash</div></div></div><h2 id="碎碎念"><a href="#碎碎念" class="headerlink" title="碎碎念"></a>碎碎念</h2><p>前些天，我对网站的样式进行了优化，包括关于页面、顶栏特效和左上角菜单等。然而，每次修改后，都需要手动按 <code>Ctrl+F5</code> 强制刷新缓存，虽然操作不复杂，但有些朋友可能并不知道 <code>Ctrl+F5</code> 可以强制刷新，导致页面样式异常。同时，浏览器会缓存样式文件，虽然缓存了内容，却没有得到充分利用。因此，我决定配置 <code>SW</code> 来实现更精细的控制。</p><p>恰好，<a target="_blank" rel="external nofollow noopener noreferrer" href="/safego/?u=aHR0cHM6Ly9rbWFyLnRvcC8">空梦</a> 大佬开发了一个功能更丰富、更加可控的 <code>SWPP</code>。相比于传统 <code>SW</code>，<code>SWPP</code> 支持 <strong>增量更新</strong>、<strong>URL 竞速</strong>、<strong>备用 URL</strong> 等强大特性。于是，我连夜缠着大佬帮我配置，最终顺利实现，真的非常感谢空梦的帮助！</p><p>可能你对这些概念还不太熟悉？别急！接下来我会逐一讲解。本篇教程的目标是让大家能够 <strong>零门槛</strong> 配置 <code>SWPP</code>，可能不会涉及一些晦涩的知识，当然我也不是很懂，如果你对底层原理感兴趣，欢迎阅读官方文档！</p><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9zd3BwLmttYXIudG9wLw" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Service Worker Plus Plus</div><div class="tag-link-sitename">一个用于为网站快速生成一个高度可用的Service Worker的工具</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><h2 id="简单介绍"><a href="#简单介绍" class="headerlink" title="简单介绍"></a>简单介绍</h2><h3 id="原生SW"><a href="#原生SW" class="headerlink" title="原生SW"></a>原生SW</h3><p>可能很多人对 <code>SW</code>（Service Worker）并不了解，甚至没听说过它的作用。简单来说，<code>SW</code> 是一种运行在浏览器后台的独立脚本，能够拦截和控制页面的网络请求，实现资源缓存、后台同步、推送通知等功能。</p><p>在默认情况下呢，浏览器会根据 HTTP 头的缓存策略来决定资源的缓存时间，但这些缓存并不受开发者的直接控制，而是由浏览器自行管理。而 <code>SW</code> 允许开发者通过编写脚本，精确控制哪些资源应该缓存、缓存多久、何时更新等，提供了更灵活的缓存管理能力。</p><p>你可以尝试在你的网站上修改一个<code>CSS</code>样式，然后推送到网站上，在缓存等全部刷新后，进入网站，样式仍然无法生效，需要手动强制刷新才能显示最新的效果，这就是浏览器的默认缓存，我们所要做的就是合理利用这部分内容，使网站更新更及时，更加节省流量，加载速度更快。</p><p>下面是原生<code>SW</code>的官方文档，你会发现比<code>SWPP</code>的理论性知识还枯燥难懂……</p><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9kZXZlbG9wZXIubW96aWxsYS5vcmcvemgtQ04vZG9jcy9XZWIvQVBJL1NlcnZpY2VfV29ya2VyX0FQSQ" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Service Worker API</div><div class="tag-link-sitename">一个注册在指定源和路径下的事件驱动worker</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><p>通常<code>SW</code>主要用于以下几个场景：</p><ul><li><strong>离线访问</strong>：即使用户断网，已缓存的资源仍然可以正常加载，提升可用性。</li><li><strong>加速页面加载</strong>：通过缓存静态资源，减少网络请求，提高页面加载速度。</li><li><strong>网络请求代理</strong>：拦截请求并根据规则决定是否从缓存返回或从服务器获取数据。</li><li><strong>后台任务处理</strong>：支持推送通知、后台数据同步等功能，提升用户体验。</li></ul><p>尽管 <code>SW</code> 具备很强的可控性，但它也可能带来一些潜在问题。如果 <code>SW</code> 配置不合理，可能会导致严重的缓存管理失误，影响用户体验。比如<strong>缓存污染</strong> 可能会使用户始终加载旧版本的资源，即使服务器已经更新，仍然无法获取最新内容。此外，<strong>更新滞后</strong> 也是经常遇到的问题，默认情况下，新的 <code>SW</code> 需要等到旧 <code>SW</code> 释放后才会生效，这可能导致网站更新无法及时反映到用户端，而<code>SWPP</code>就解决了这些痛点，我们可以自行定义缓存过期时间，并且可以实现增量更新，也就是网站更新后，前端检测自动刷新相关的文件缓存，实现高度可用。</p><h3 id="SWPP优点"><a href="#SWPP优点" class="headerlink" title="SWPP优点"></a>SWPP优点</h3><p>这里图方便，我直接给官方文档里的区别图搬过来啦，后面会大概讲解其中的主要内容。</p><table><thead><tr><th align="center">\</th><th align="center">swpp@3</th><th align="center">swpp@2</th><th align="center">hexo-offline</th></tr></thead><tbody><tr><td align="center">本地缓存</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">✔️</td></tr><tr><td align="center">缓存增量更新</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">缓存过期时间</td><td align="center">✔️</td><td align="center">❌</td><td align="center">✔️</td></tr><tr><td align="center">缓存大小限制</td><td align="center">❌</td><td align="center">❌</td><td align="center">✔️</td></tr><tr><td align="center">预缓存</td><td align="center">❌</td><td align="center">❌</td><td align="center">✔️</td></tr><tr><td align="center">Request 篡改</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">URL 竞速</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">备用 URL</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">204 阻塞响应</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">逃生门</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">请求合并</td><td align="center">❌</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">高度自由</td><td align="center">✔️</td><td align="center">✔️</td><td align="center">❌</td></tr><tr><td align="center">更新</td><td align="center">活跃</td><td align="center">停止维护</td><td align="center">超过两年没有更新</td></tr></tbody></table><ol><li><p><strong>本地缓存</strong>：最基本的功能，将网站上的文件缓存到<code>Cache</code>中，提高访问速度，高度利用浏览器的默认缓存机制，你可以按照下图寻找该站的缓存：</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e57635ce0b2.webp" alt="本站缓存"></p></li><li><p><strong>增量更新</strong>：通常情况下，缓存更新的方式是完全替换旧的缓存，而增量更新允许只替换部分资源，比如本次更新我修改了<code>index.css</code>，在构建的过程中，会对比其前后的哈希值，如果该文件哈希值发生问题，就会更新该文件，所以**<code>swpp</code>命令建议在压缩后执行**，因为压缩的结果可能每次都不一样，会导致误检测所有文件都需要更新。</p></li><li><p><strong>缓存过期时间</strong>、<strong>缓存大小限制</strong>：忒好理解了，跳过跳过~</p></li><li><p><strong>预缓存</strong>：预缓存指的是在 <code>SW</code> 安装时就提前缓存一部分资源，以便离线时可以直接加载。不过，对于经常更新的网站，预缓存可能会导致旧资源无法及时清理，因此不一定适合所有场景。</p></li><li><p><strong>Request篡改</strong>：允许开发者拦截和修改浏览器的请求，比如动态修改 URL、添加自定义请求头等。这对于调试、数据代理和 CDN 适配等场景非常有用，比如我们可以通过修改<code>jsdelivr</code>的请求到国内现有镜像站，加快访问速度。</p></li><li><p><strong>备用URL</strong>：当某个资源加载失败时，备用<code>URL</code>可以提供一个替代方案，避免页面崩溃。例如，如果主服务器宕机，可以自动切换到备选服务器加载资源，某个镜像站突然访问不了，<code>SW</code>可以自动切换到另一个镜像站进行请求，实现高度稳定性。</p></li><li><p><strong>204阻塞响应</strong>：反正我是没懂，下面是<code>GPT</code>的解释，该功能用于阻止不必要的请求，减少服务器负担。</p></li><li><p><strong>逃生门</strong>：当你的<code>SW</code>实现错误导致无法发送消息，且<code>DOM</code>被错误的永久缓存，那么靠普通手段是完全没有办法解决这个死循环的，逃生门的作用就是触发时强制更新缓存来解开这个死局。</p></li><li><p><strong>请求合并</strong>：允许多个相似的请求合并成一个，减少网络请求数量，不过目前这个功能基本上都是在网络层更好实现，比兔合并<code>TCP</code>请求，减少握手挥手次数，这样看来，前端的实现就变得可有可无了。</p></li></ol><p>以上就是大部分的内容，我个人感觉是可以简单的理解的，虽然半知半解但是至少懂了这个是干嘛的！那么我们就可以进入下一部分啦！开始配置！</p><h2 id="开始配置"><a href="#开始配置" class="headerlink" title="开始配置"></a>开始配置</h2><h3 id="插件安装"><a href="#插件安装" class="headerlink" title="插件安装"></a>插件安装</h3><p><code>swpp</code>还在开发阶段，目前更新的均为开发版本的内容，但是经过前些天的更新，本站的测试，开发版基本上没有任何问题，所以该教程将基于最新版本的<code>SWPP</code>进行讲解。</p><p>首先下载包，这里我们选择<code>Hexo</code>插件，所以除了必要的后端包，还需要<code>Hexo-swpp</code>插件，在博客根目录执行以下命令：</p><figure class="highlight bash"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm install swpp-backends@3.0.0-alpha.906 --save</span><br><span class="line">npm install hexo-swpp@4.0.0-alpha.131 --save</span><br></pre></td></tr></tbody></table></figure><p>下面开始配置，在<strong>Hexo配置文件</strong><code>_config.yml</code>中添加以下内容，注意不是主题配置文件：</p><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">swpp:</span></span><br><span class="line">  <span class="comment"># 是否启用，默认 false</span></span><br><span class="line">  <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 配置文件路径，以 `/` 结尾表示加载指定文件夹下的所有文件，注意文件夹中只能有配置文件，不能有其它文件及文件夹</span></span><br><span class="line">  <span class="attr">config_path:</span> <span class="string">'swpp.config.ts'</span></span><br><span class="line">  <span class="comment"># 是否生成 sw</span></span><br><span class="line">  <span class="attr">serviceWorker:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 是否向所有 HTML 插入注册 sw 的代码</span></span><br><span class="line">  <span class="attr">auto_register:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 是否生成 DOM 端的 JS 文件并在 HTML 中插入 script</span></span><br><span class="line">  <span class="attr">gen_dom:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 是否追踪链接，默认 false</span></span><br><span class="line">  <span class="comment"># ⚠️警告！！！未启用链接追踪时不要使用永久缓存，否则会导致被缓存的数据永远不会更新，在您不再使用该资源时，缓存也不会被删除！！！</span></span><br><span class="line">  <span class="attr">track_link:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># 生成的 diff 文件的路径（可以是绝对路径也可以是相对路径，使用相对路径时相对于网站发布目录），留空表示不生成（默认为 null）</span></span><br><span class="line">  <span class="attr">gen_diff:</span> <span class="string">'./diff.json'</span></span><br><span class="line">  <span class="comment"># 是否在执行 hexo deploy 时自动执行 swpp 指令</span></span><br><span class="line">  <span class="comment"># auto_exec: false</span></span><br><span class="line">  <span class="comment"># 检查更新的网址，默认 "https://registry.npmjs.org"，注意不能以斜杠结尾</span></span><br><span class="line">  <span class="attr">npm_url:</span> <span class="string">'https://registry.npmmirror.com'</span></span><br><span class="line">  <span class="comment">#</span></span><br><span class="line">  <span class="comment"># 排序规则。</span></span><br><span class="line">  <span class="comment"># 该配置项是为了对 hexo 中的一些变量进行排序，避免每次生成 HTML 时由于这些变量的顺序变动导致生成结果不完全相同。</span></span><br><span class="line">  <span class="comment"># 示例：</span></span><br><span class="line">  <span class="comment"># ```yaml</span></span><br><span class="line">  <span class="comment"># # 下面给出的值为插件的缺省值，用户设置该项不会直接覆盖这些值，只有用户也声明 posts、pages 或 tags 时才会覆盖对应的值。</span></span><br><span class="line">  <span class="comment"># swpp:</span></span><br><span class="line">  <span class="comment">#   sort_rules:</span></span><br><span class="line">  <span class="comment">#     posts: 'title'</span></span><br><span class="line">  <span class="comment">#     pages: 'title'</span></span><br><span class="line">  <span class="comment">#     tags: 'name'</span></span><br><span class="line">  <span class="comment"># ```</span></span><br><span class="line">  <span class="comment"># 其中 key 值为要排序的变量的名称，value 为变量排序时的依据，</span></span><br><span class="line">  <span class="comment"># 填 false 表示禁用该项排序，填 true 表示以 value 本身为键进行排序，填字符串表示以 value[tag] 为键进行排序。</span></span><br><span class="line">  <span class="comment"># sort_rules:</span></span><br></pre></td></tr></tbody></table></figure><p>以上是本站配置，其余配置请按照自身需要去开，建议和本站一致，备注写的很详细，不太懂的按照本站配置即可。</p><p>其中<code>track_link</code>是增量更新的配置，如果设置为<code>false</code>将严格按照缓存时间进行过期，不会自动检测并更新文件，建议开启。</p><h3 id="插件配置"><a href="#插件配置" class="headerlink" title="插件配置"></a>插件配置</h3><div class="note note-warning"><div class="note-header"><i class="note-icon fa-regular fa-circle-dot"></i> <span class="note-title">注意</span></div><div class="note-content"><p><strong>注意</strong>，错误的缓存配置可能会导致部分该阶段访问的用户无法查看更新内容，请小心谨慎的配置！！！</p></div></div><p><code>SWPP</code>还需要一个配置文件，来控制我们所需要的功能，在博客根目录下创建文件<code>swpp.config.ts</code>，当然也支持其他类型的配置文件比如：<code>ts</code>、<code>js</code>、<code>mts</code>、<code>cts</code>、<code>mjs</code>、<code>cjs</code>，完全没区别，这里我以<code>ts</code>为例。</p><div class="note note-info"><div class="note-header"><i class="note-icon fa-regular fa-circle-check"></i> <span class="note-title">配置文件说明</span></div><div class="note-content"><p>由于配置文件配置难度较高，为了大家更为方便的实现功能，我建议直接基于我的配置文件实现，该文件包含大部分实用功能，如果有更高的要求可以自行查看文档进行适配。</p></div></div><p>在文件中写入以下内容：</p><figure class="highlight typescript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> {</span><br><span class="line">    defineConfig</span><br><span class="line">} <span class="keyword">from</span> <span class="string">'swpp-backends'</span></span><br><span class="line"></span><br><span class="line"><span class="title function_">defineConfig</span>({</span><br><span class="line">    <span class="attr">compilationEnv</span>: {</span><br><span class="line">        <span class="attr">DOMAIN_HOST</span>: <span class="keyword">new</span> <span class="title function_">URL</span>(<span class="string">'https://blog.liushen.fun'</span>),</span><br><span class="line">        <span class="attr">SERVICE_WORKER</span>: <span class="string">"sw"</span>,</span><br><span class="line">        <span class="title class_">JSON</span><span class="attr">_HTML_LIMIT</span>: <span class="number">10</span>,</span><br><span class="line">        <span class="attr">isStable</span>: <span class="function">(<span class="params"><span class="attr">url</span>: URL</span>) =&gt;</span> {</span><br><span class="line">            <span class="keyword">return</span> [</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)(cdn|fastly)\.jsdelivr\.net\/npm\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)jsd\.example\.com\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)cdn\.jsdmirror\.com\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)cdn\.staticfile\.org\/.*\/\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)lf\d+-cdn-tos\.bytecdntp\.com\/.*\/\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)npm\.elemecdn\.com\/.*@\d+\.\d+\.\d+\//</span></span><br><span class="line">            ].<span class="title function_">some</span>(<span class="function"><span class="params">it</span> =&gt;</span> it.<span class="title function_">test</span>(url.<span class="property">href</span>))</span><br><span class="line">        },</span><br><span class="line">        <span class="attr">VERSION_LENGTH_LIMIT</span>: <span class="number">512</span>,</span><br><span class="line">        <span class="attr">NETWORK_FILE_FETCHER</span>: {</span><br><span class="line">            <span class="attr">referer</span>: <span class="string">"https://blog.liushen.fun"</span>,</span><br><span class="line">            <span class="title function_">getStandbyList</span>(<span class="attr">url</span>: <span class="built_in">string</span> | <span class="variable constant_">URL</span>): (<span class="built_in">string</span> | <span class="variable constant_">URL</span>)[] {</span><br><span class="line">                <span class="keyword">if</span> (<span class="keyword">typeof</span> url === <span class="string">'string'</span>) url = <span class="keyword">new</span> <span class="title function_">URL</span>(url)</span><br><span class="line">                <span class="keyword">if</span> (url.<span class="property">hostname</span> === <span class="string">'npm.elemecdn.com'</span>) {</span><br><span class="line">                    <span class="keyword">return</span> [<span class="string">`https://fastly.jsdelivr.net<span class="subst">${url.pathname}</span>`</span>]</span><br><span class="line">                }</span><br><span class="line">                <span class="keyword">return</span> [url]</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    },</span><br><span class="line"></span><br><span class="line">    <span class="attr">crossEnv</span>: {</span><br><span class="line">        <span class="attr">CACHE_NAME</span>: <span class="string">"BlogCache"</span>,</span><br><span class="line">        <span class="attr">VERSION_PATH</span>: <span class="string">"https://id.v3/"</span>,</span><br><span class="line">        <span class="attr">ESCAPE</span>: <span class="number">15</span>,</span><br><span class="line">    },</span><br><span class="line"></span><br><span class="line">    <span class="attr">runtimeDep</span>: {</span><br><span class="line">        <span class="attr">getStandbyRequests</span>: (<span class="attr">request</span>: <span class="title class_">Request</span>): {<span class="attr">t</span>: <span class="built_in">number</span>, <span class="attr">l</span>: <span class="function">() =&gt;</span> <span class="title class_">Request</span>[]} | <span class="function"><span class="params">void</span> =&gt;</span> {</span><br><span class="line">            <span class="keyword">const</span> srcUrl = request.<span class="property">url</span></span><br><span class="line">            <span class="keyword">const</span> {host, pathname} = <span class="keyword">new</span> <span class="title function_">URL</span>(srcUrl)</span><br><span class="line">            <span class="comment">// noinspection SpellCheckingInspection</span></span><br><span class="line">            <span class="keyword">const</span> commonCdnList = [<span class="string">'jsd.example.com'</span>, <span class="string">'cdn.jsdmirror.com'</span>, <span class="string">'fastly.jsdelivr.net'</span>]</span><br><span class="line">            <span class="comment">// noinspection SpellCheckingInspection</span></span><br><span class="line">            <span class="keyword">const</span> elme = <span class="string">'npm.elemecdn.com'</span></span><br><span class="line">            <span class="keyword">const</span> <span class="title function_">urlMapper</span> = (<span class="params"><span class="attr">it</span>: <span class="built_in">string</span></span>) =&gt; <span class="keyword">new</span> <span class="title class_">Request</span>(it, request)</span><br><span class="line">            <span class="keyword">if</span> (host === elme) {</span><br><span class="line">                <span class="keyword">return</span> {</span><br><span class="line">                    <span class="attr">t</span>: <span class="number">2000</span>,</span><br><span class="line">                    <span class="attr">l</span>: <span class="function">() =&gt;</span> [...commonCdnList.<span class="title function_">map</span>(<span class="function"><span class="params">it</span> =&gt;</span> <span class="string">`https://<span class="subst">${it}</span>/npm<span class="subst">${pathname}</span>`</span>)].<span class="title function_">map</span>(urlMapper)</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">            <span class="keyword">if</span> (host === <span class="string">'jsd.example.com'</span>) {</span><br><span class="line">                commonCdnList.<span class="title function_">splice</span>(<span class="number">0</span>, <span class="number">1</span>)</span><br><span class="line">                <span class="keyword">return</span> {</span><br><span class="line">                    <span class="attr">t</span>: <span class="number">2000</span>,</span><br><span class="line">                    <span class="attr">l</span>: <span class="function">() =&gt;</span> [...commonCdnList.<span class="title function_">map</span>(<span class="function"><span class="params">it</span> =&gt;</span> <span class="string">`https://<span class="subst">${it}</span><span class="subst">${pathname}</span>`</span>)].<span class="title function_">map</span>(urlMapper)</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    },</span><br><span class="line"></span><br><span class="line">    <span class="attr">crossDep</span>: {</span><br><span class="line">        <span class="attr">matchCacheRule</span>: {</span><br><span class="line">            <span class="attr">runOnBrowser</span>: <span class="function">(<span class="params"><span class="attr">url</span>: URL</span>)  =&gt;</span> {</span><br><span class="line">                <span class="keyword">let</span> { host, pathname } = url;</span><br><span class="line"></span><br><span class="line">                <span class="comment">// 处理省略index.html的情况</span></span><br><span class="line">                <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'/'</span>)) pathname += <span class="string">'index.html'</span>;</span><br><span class="line"></span><br><span class="line">                <span class="comment">// 仅仅对于blog.liushen.fun 处理 html 和 json</span></span><br><span class="line">                <span class="keyword">if</span> (host.<span class="title function_">endsWith</span>(<span class="string">'blog.liushen.fun'</span>)) {</span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.json'</span>)) <span class="keyword">return</span> <span class="number">3600000</span>; <span class="comment">// 1 hour</span></span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.html'</span>)) <span class="keyword">return</span> <span class="literal">false</span>; <span class="comment">// 暂不缓存</span></span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.webp'</span>) || pathname.<span class="title function_">endsWith</span>(<span class="string">'.jpg'</span>) || pathname.<span class="title function_">endsWith</span>(<span class="string">'.png'</span>)) <span class="keyword">return</span> <span class="number">43200000</span>; <span class="comment">// 12 hours</span></span><br><span class="line">                }</span><br><span class="line">                <span class="keyword">if</span> (<span class="regexp">/\.(js|css|woff2|woff|ttf|cur)$/</span>.<span class="title function_">test</span>(url.<span class="property">pathname</span>)) <span class="keyword">return</span> <span class="number">172800000</span>; <span class="comment">// 2 days</span></span><br><span class="line">                </span><br><span class="line">                <span class="comment">// return ((url.host.endsWith('blog.liushen.fun') &amp;&amp; /(\/|\.json)$/.test(url.pathname)) || /\.(js|css|woff2|woff|ttf|cur)$/.test(url.pathname)) ? 86400000 : false</span></span><br><span class="line">            },</span><br><span class="line">            <span class="title function_">runOnNode</span>(<span class="params"><span class="attr">url</span>: URL</span>) {</span><br><span class="line">                <span class="comment">// @ts-ignore</span></span><br><span class="line">                <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="title function_">runOnBrowser</span>(url)</span><br><span class="line">            }</span><br><span class="line">        }</span><br><span class="line">    },</span><br><span class="line">})</span><br></pre></td></tr></tbody></table></figure><p>以上是我的配置，下面我会详细讲解需要修改哪里。</p><h4 id="DOMAIN-HOST"><a href="#DOMAIN-HOST" class="headerlink" title="DOMAIN_HOST"></a>DOMAIN_HOST</h4><p>必须改的部分，这个应该都能理解，所以这里我就不讲了。</p><h4 id="isStable"><a href="#isStable" class="headerlink" title="isStable"></a>isStable</h4><p>你需要改的首先就是<code>isStable</code>部分，这部分的内容是判断该内容是否为永久不变的内容，比如<code>jsdelivr</code>加了版本号的文件，一般是不会变动的，这就是稳定内容，所以请自行替换<code>jsd.example.com</code>一行的匹配或者直接删掉，这里的通配符尽量覆盖贵站的所有<code>JSD</code>资源。</p><figure class="highlight typescript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">isStable</span>: <span class="function">(<span class="params"><span class="attr">url</span>: URL</span>) =&gt;</span> {</span><br><span class="line">            <span class="keyword">return</span> [</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)(cdn|fastly)\.jsdelivr\.net\/npm\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)jsd\.example\.com\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)cdn\.jsdmirror\.com\/.*@\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)cdn\.staticfile\.org\/.*\/\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)lf\d+-cdn-tos\.bytecdntp\.com\/.*\/\d+\.\d+\.\d+\//</span>,</span><br><span class="line">                <span class="regexp">/^(https?:\/\/|\/\/)npm\.elemecdn\.com\/.*@\d+\.\d+\.\d+\//</span></span><br><span class="line">            ].<span class="title function_">some</span>(<span class="function"><span class="params">it</span> =&gt;</span> it.<span class="title function_">test</span>(url.<span class="property">href</span>))</span><br><span class="line">        },</span><br></pre></td></tr></tbody></table></figure><p>这里我建议大家不要在配置文件中修改某个文件的地址，而是统一替换，下面文章中有教程，欢迎阅读，<strong>注意原文中的智云加速可能无法使用</strong>，请自行替换为<strong>文章头部其他的镜像站</strong>，使用和配置方式是完全一样的，只需要替换链接即可。</p><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="https://blog.liushen.fun/posts/cd89007e/"><div class="tag-link-tips">😃来自本站，本站可确保其安全性，请放心点击跳转</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/08/01/66aae601dbc9b.webp)"></div><div class="tag-link-right"><div class="tag-link-title">智云加速--JSDelivr国内公益加速镜像</div><div class="tag-link-sitename">LiuShen's Blog</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><p>推荐这样配置的原因是可以加速所有的静态，不需要一个个配置，非常整齐，并且比如<code>Butterfly</code>主题会对该资源所在站点进行预加载，可以稍微加快访问速度，如果一个个配置可能无法达到良好的效果，再者就是，在<code>SWPP</code>的<code>isStable</code>函数中，可以更少的通配符即可匹配所有的稳定资源地址。</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e63913caf6e.webp" alt="Preconnect标签"></p><p>当然，还是按照自己的站点自行配置，如果有问题欢迎在评论区讨论！</p><h4 id="referer"><a href="#referer" class="headerlink" title="referer"></a>referer</h4><p>如果你使用的是自己反代的一些资源，可能会挂上防盗链防止盗刷，会导致后端对比文件差异时无法拉取到文件导致报错，所以<code>SWPP</code>提供了<code>Referer</code>选项，按照自身要求填写即可。</p><h4 id="getStandbyRequests"><a href="#getStandbyRequests" class="headerlink" title="getStandbyRequests"></a>getStandbyRequests</h4><p>该项用于启用备用 URL，返回任意转换为 <code>false</code> 值均表示对于给定的资源不启用备用 URL，这里我建议开启，指向一些备用<code>jsd</code>镜像站，这里我仍然使用<code>jsd.example.com</code>作为<code>jsd</code>镜像站为举例，自行替换即可。</p><figure class="highlight typescript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">getStandbyRequests</span>: (<span class="attr">request</span>: <span class="title class_">Request</span>): {<span class="attr">t</span>: <span class="built_in">number</span>, <span class="attr">l</span>: <span class="function">() =&gt;</span> <span class="title class_">Request</span>[]} | <span class="function"><span class="params">void</span> =&gt;</span> {</span><br><span class="line">            <span class="keyword">const</span> srcUrl = request.<span class="property">url</span></span><br><span class="line">            <span class="keyword">const</span> {host, pathname} = <span class="keyword">new</span> <span class="title function_">URL</span>(srcUrl)</span><br><span class="line">            <span class="comment">// noinspection SpellCheckingInspection</span></span><br><span class="line">            <span class="keyword">const</span> commonCdnList = [<span class="string">'jsd.example.com'</span>, <span class="string">'cdn.jsdmirror.com'</span>, <span class="string">'fastly.jsdelivr.net'</span>]</span><br><span class="line">            <span class="comment">// noinspection SpellCheckingInspection</span></span><br><span class="line">            <span class="keyword">const</span> elme = <span class="string">'npm.elemecdn.com'</span></span><br><span class="line">            <span class="keyword">const</span> <span class="title function_">urlMapper</span> = (<span class="params"><span class="attr">it</span>: <span class="built_in">string</span></span>) =&gt; <span class="keyword">new</span> <span class="title class_">Request</span>(it, request)</span><br><span class="line">            <span class="keyword">if</span> (host === elme) {</span><br><span class="line">                <span class="keyword">return</span> {</span><br><span class="line">                    <span class="attr">t</span>: <span class="number">2000</span>,</span><br><span class="line">                    <span class="attr">l</span>: <span class="function">() =&gt;</span> [...commonCdnList.<span class="title function_">map</span>(<span class="function"><span class="params">it</span> =&gt;</span> <span class="string">`https://<span class="subst">${it}</span>/npm<span class="subst">${pathname}</span>`</span>)].<span class="title function_">map</span>(urlMapper)</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">            <span class="keyword">if</span> (host === <span class="string">'jsd.example.com'</span>) {</span><br><span class="line">                commonCdnList.<span class="title function_">splice</span>(<span class="number">0</span>, <span class="number">1</span>)</span><br><span class="line">                <span class="keyword">return</span> {</span><br><span class="line">                    <span class="attr">t</span>: <span class="number">2000</span>,</span><br><span class="line">                    <span class="attr">l</span>: <span class="function">() =&gt;</span> [...commonCdnList.<span class="title function_">map</span>(<span class="function"><span class="params">it</span> =&gt;</span> <span class="string">`https://<span class="subst">${it}</span><span class="subst">${pathname}</span>`</span>)].<span class="title function_">map</span>(urlMapper)</span><br><span class="line">                }</span><br><span class="line">            }</span><br><span class="line">        }</span><br></pre></td></tr></tbody></table></figure><h4 id="matchCacheRule"><a href="#matchCacheRule" class="headerlink" title="matchCacheRule"></a>matchCacheRule</h4><p>该项用于判断一个资源是否需要被前端缓存，其中各个返回值的含义如下：</p><ul><li><code>false</code> <code>null</code> <code>undefined</code> 或 <code>0</code>：表示不需要缓存。</li><li>正数：表示需要缓存，缓存类型为定时缓存，单位为毫秒，超过指定时间后缓存自动失效。</li><li><code>INFINITE_CACHE</code>：表示需要缓存，缓存类型为永久缓存，仅能通过增量更新失效。</li></ul><div class="note note-warning"><div class="note-header"><i class="note-icon fa-regular fa-circle-dot"></i> <span class="note-title">警告</span></div><div class="note-content"><p>请勿返回负数！使用无限期缓存请返回 <code>INFINITE_CACHE</code>，<code>INFINITE_CACHE</code> 是一个 Symbol 类型的常量。</p><p>无限期缓存谨慎使用，可能造成没必要的资源永久堆积。</p></div></div><p>比如以下例子，对于本站内的资源，我分别配置了<code>json</code>、<code>html</code>、<code>webp|jpg|png</code>图片的缓存，防止因为永久缓存导致缓存量过大，对于站外的静态资源，缓存时间我设置为了两天，注意这里的单位是<code>毫秒ms</code>，如果你想修改，请按照要求自行填写。</p><figure class="highlight typescript"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">matchCacheRule</span>: {</span><br><span class="line">            <span class="attr">runOnBrowser</span>: <span class="function">(<span class="params"><span class="attr">url</span>: URL</span>)  =&gt;</span> {</span><br><span class="line">                <span class="keyword">let</span> { host, pathname } = url;</span><br><span class="line"></span><br><span class="line">                <span class="comment">// 处理省略index.html的情况</span></span><br><span class="line">                <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'/'</span>)) pathname += <span class="string">'index.html'</span>;</span><br><span class="line"></span><br><span class="line">                <span class="comment">// 仅仅对于blog.liushen.fun 处理 html 和 json</span></span><br><span class="line">                <span class="keyword">if</span> (host.<span class="title function_">endsWith</span>(<span class="string">'blog.liushen.fun'</span>)) {</span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.json'</span>)) <span class="keyword">return</span> <span class="number">3600000</span>; <span class="comment">// 1 hour</span></span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.html'</span>)) <span class="keyword">return</span> <span class="literal">false</span>; <span class="comment">// 暂不缓存</span></span><br><span class="line">                    <span class="keyword">if</span> (pathname.<span class="title function_">endsWith</span>(<span class="string">'.webp'</span>) || pathname.<span class="title function_">endsWith</span>(<span class="string">'.jpg'</span>) || pathname.<span class="title function_">endsWith</span>(<span class="string">'.png'</span>)) <span class="keyword">return</span> <span class="number">43200000</span>; <span class="comment">// 12 hours</span></span><br><span class="line">                }</span><br><span class="line">                <span class="keyword">if</span> (<span class="regexp">/\.(js|css|woff2|woff|ttf|cur)$/</span>.<span class="title function_">test</span>(url.<span class="property">pathname</span>)) <span class="keyword">return</span> <span class="number">172800000</span>; <span class="comment">// 2 days</span></span><br><span class="line">                </span><br><span class="line">                <span class="comment">// return ((url.host.endsWith('blog.liushen.fun') &amp;&amp; /(\/|\.json)$/.test(url.pathname)) || /\.(js|css|woff2|woff|ttf|cur)$/.test(url.pathname)) ? 86400000 : false</span></span><br><span class="line">            },</span><br><span class="line">            <span class="title function_">runOnNode</span>(<span class="params"><span class="attr">url</span>: URL</span>) {</span><br><span class="line">                <span class="comment">// @ts-ignore</span></span><br><span class="line">                <span class="keyword">return</span> <span class="variable language_">this</span>.<span class="title function_">runOnBrowser</span>(url)</span><br><span class="line">            }</span><br><span class="line">        }</span><br></pre></td></tr></tbody></table></figure><p>这样，我们的<code>swpp</code>应该就配置成功了，注意，部署的过程中，无论是<code>Github action</code>也好，<code>Vercel</code>也罢，应该都需要执行<code>hexo generate</code>或者<code>npm run build</code>命令生成静态文件，在这两个命令后，紧跟一个<code>hexo swpp</code>命令，使其可以在构建静态文件后自动检测是否有文件需要更新并将检测结果保存到了静态文件中的<code>/swpp/</code>路径下，比如本站的<a href="https://blog.liushen.fun/swpp/update.json">update.json</a>文件，感兴趣自行点击查看。</p><p>比如<code>github action</code>构建的方式，可以尝试在这里添加一个<code>hexo swpp</code>的命令以达到效果：</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e63d864beaf.webp" alt="github action实现swpp构建"></p><p><strong>注意该命令需要在压缩命令之前执行。</strong></p><p>第一次执行<code>hexo swpp</code>命令可能出现问题，是正常现象，如下：</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e63e3255529.webp" alt="hexo swpp第一次"></p><p>如果正常构建完成后，<code>swpp</code>在下次构建中会检测所有文件的哈希值，对比是否有改动，然后选择性增量更新，这样，我们的<code>SWPP</code>就实现成功啦！</p><h3 id="查看效果"><a href="#查看效果" class="headerlink" title="查看效果"></a>查看效果</h3><p>部署到前端后，你可以<code>F12</code>打开控制台，点击应用，查看缓存空间，不出所料，会出现一个名为<code>BlogCache</code>的内容，后面有每一项的缓存时间，你可以尝试更新一下<code>css</code>然后再到前端刷新，不出所料，在博客的<code>/swpp/update.json</code>会看到对应的修改文件的后半部分，在前端你也会看到<code>CSS</code>的缓存时间更新了，这就是增量更新生效了，当然缓存刷新有一定的CD，默认为十分钟，可以尝试部署成功后，十分钟后再测试。</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e63fd6ce576.webp" alt="缓存空间位置"></p><h2 id="PWA实现"><a href="#PWA实现" class="headerlink" title="PWA实现"></a>PWA实现</h2><p>PWA（渐进式 Web 应用，Progressive Web App）是一种让网站拥有接近原生应用体验的技术。它结合了网页的灵活性和<code>App</code>的优势，使得用户可以像使用手机应用一样访问和操作网站，而不需要额外下载和安装。</p><p>一个<code>PWA</code>网站可以在<strong>离线状态下继续运行</strong>，这得益于<code>Service Worker</code>技术，它能够缓存关键资源，使网页即使在没有网络的情况下也能正常加载。与此同时，<code>PWA</code>还可以支持<strong>安装到桌面或手机主屏幕</strong>，用户打开时不会看到浏览器的<code>UI</code>，而是像独立的<code>App</code>一样运行，这种体验可以增强用户的沉浸感。<code>PWA</code>还可以通过优化缓存和请求管理，让页面加载更快，减少流量消耗，提高交互流畅度。</p><p>在功能扩展方面，<code>PWA</code>还能支持<strong>推送通知</strong>，允许网站主动向用户发送消息，增强互动性。不过，这一功能需要额外的服务器支持。</p><p>当然以上功能需要和缓存策略结合，比如本站并没有缓存<code>html</code>文件，所以可能达不到离线运行的效果，当然你可以自行定制化。</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e64226188f5.webp" alt="PWA应用"></p><p>你的站点已经通过<code>SWPP</code>实现了缓存优化和更细粒度的控制，这正是<code>PWA</code>的重要组成部分。如果进一步配置 <code>manifest.json</code>，即可实现<code>PWA</code>。</p><h3 id="头部信息"><a href="#头部信息" class="headerlink" title="头部信息"></a>头部信息</h3><p>这里我们以<code>Hexo-theme-butterfly</code>为示例，<code>btf</code>中很好的集成了<code>PWA</code>，首先，修改主题配置文件的<code>PWA</code>部分配置：</p><figure class="highlight yaml"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># PWA</span></span><br><span class="line"><span class="comment"># 查看 https://github.com/JLHwung/hexo-offline</span></span><br><span class="line"><span class="comment"># ---------------</span></span><br><span class="line"><span class="attr">pwa:</span></span><br><span class="line">  <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line">  <span class="attr">manifest:</span> <span class="string">/manifest.json</span></span><br><span class="line">  <span class="attr">apple_touch_icon:</span> <span class="string">/apple-touch-icon.png</span></span><br><span class="line">  <span class="attr">favicon_32_32:</span> <span class="string">/config/img/pwa/favicon-32x32.png</span></span><br><span class="line">  <span class="attr">favicon_16_16:</span> <span class="string">/config/img/pwa/favicon-16x16.png</span></span><br><span class="line">  <span class="attr">mask_icon:</span> <span class="string">/config/img/pwa/favicon-mask.svg</span></span><br></pre></td></tr></tbody></table></figure><p>图标注意一一对应，<code>mask.svg</code>实测似乎并没用到哪里，所以其实可有可无，可以先配置，<code>svg</code>任意放置一个即可。</p><h3 id="manifest-json"><a href="#manifest-json" class="headerlink" title="manifest.json"></a>manifest.json</h3><p>在<code>source</code>文件夹下创建<code>manifest.json</code>，写入以下内容：</p><figure class="highlight json"><table><tbody><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">{</span></span><br><span class="line">    <span class="attr">"lang"</span><span class="punctuation">:</span> <span class="string">"en"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"name"</span><span class="punctuation">:</span> <span class="string">"清羽飞扬"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"short_name"</span><span class="punctuation">:</span> <span class="string">"清羽飞扬"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"description"</span><span class="punctuation">:</span> <span class="string">"blog.liushen.fun"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"theme_color"</span><span class="punctuation">:</span> <span class="string">"#242424"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"background_color"</span><span class="punctuation">:</span> <span class="string">"#242424"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"display"</span><span class="punctuation">:</span> <span class="string">"standalone"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"scope"</span><span class="punctuation">:</span> <span class="string">"/"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"start_url"</span><span class="punctuation">:</span> <span class="string">"/"</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">"icons"</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-36x36.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"36x36"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-48x48.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"48x48"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-72x72.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"72x72"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-96x96.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"96x96"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-144x144.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"144x144"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-192x192.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"192x192"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-256x256.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"256x256"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-384x384.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"384x384"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span><span class="punctuation">,</span></span><br><span class="line">        <span class="punctuation">{</span></span><br><span class="line">            <span class="attr">"src"</span><span class="punctuation">:</span> <span class="string">"/config/img/pwa/favicon-512x512.png"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"sizes"</span><span class="punctuation">:</span> <span class="string">"512x512"</span><span class="punctuation">,</span></span><br><span class="line">            <span class="attr">"type"</span><span class="punctuation">:</span> <span class="string">"image/png"</span></span><br><span class="line">        <span class="punctuation">}</span></span><br><span class="line">    <span class="punctuation">]</span></span><br><span class="line"><span class="punctuation">}</span></span><br></pre></td></tr></tbody></table></figure><p>修改网站标题和网站<code>url</code>，图标使用相对位置定义，如果有部分图标尺寸不存在，可以删除，但是尽量全部配置，<strong>不要使用网络地址！！！</strong>。</p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e6496111db6.webp" alt="图标展示"></p><p><del>我也不知道16x16是为了实现啥，完全看不清了都！</del></p><p>如此配置好后，再次更新网站，你应该就可以看到地址栏最右侧的安装按钮，这表明网站配置完毕，如果无法看到，可以右键删除缓存，重新生成一次，相信可以做到理想的效果。</p><p>教程结束！</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>在空梦大佬的帮助下，我成功配置了<code>SWPP</code>，让网站的缓存管理更加灵活，访问速度更快，同时也实现了一定程度的离线支持。现在，即使改动了样式或脚本，也不用再担心用户访问时加载的还是旧版本的资源，体验提升了不少。</p><p>不过，<code>SW</code>这个东西确实是把双刃剑，配置得好，网站快如闪电，访问体验拉满，尤其适合一些部署在<code>Vercel</code>或者<code>CF Page</code>的站长，缓存到本地可以极大的解决源站访问缓慢的问题；但如果配置不当，可能会导致用户长时间看不到最新内容，甚至页面直接炸裂，怎么刷新都没用。有些极端情况下，错误的 SW 逻辑甚至可能让用户卡在旧版本里无法更新，除非手动清除缓存，影响体验不说，还容易劝退一部分访客。所以，虽然<code>SW</code>很香，但在使用时必须保持谨慎，确保更新机制合理，避免给用户带来困扰。</p><p>最后，感谢空梦大佬的帮助！</p><h2 id="参考文章"><a href="#参考文章" class="headerlink" title="参考文章"></a>参考文章</h2><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9zd3BwLmttYXIudG9wLw" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">SWPP官方文档</div><div class="tag-link-sitename">一个用于为网站快速生成一个高度可用的Service Worker的工具</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9rbWFyLnRvcC9wb3N0cy9iNzBlYzg4Zi8" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">Swpp Backends官方文档</div><div class="tag-link-sitename">山岳库博</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9naXRodWIuY29tL0VtcHR5RHJlYW1zL2hleG8tc3dwcCNyZWFkbWU" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a461a3098aa.webp)"></div><div class="tag-link-right"><div class="tag-link-title">为 Hexo 博客自动构建 ServiceWorker！</div><div class="tag-link-sitename">github.com@EmptyDreams</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><div class="liushen-tag-link"><a class="tag-Link" target="_blank" href="/safego/?u=aHR0cHM6Ly9rbWFyLnRvcC9wb3N0cy85NGEwZjI2Zi8" rel="external nofollow noopener noreferrer"><div class="tag-link-tips">🙄引用站外地址，不保证站点的可用性和安全性</div><div class="tag-link-bottom"><div class="tag-link-left" style="background-image:url(https://p.liiiu.cn/i/2024/07/27/66a4632bbf06e.webp)"></div><div class="tag-link-right"><div class="tag-link-title">基于Butterfly的PWA适配</div><div class="tag-link-sitename">山岳库博</div></div><i class="fa-solid fa-angle-right"></i></div></a></div><h2 id="每日一图"><a href="#每日一图" class="headerlink" title="每日一图"></a>每日一图</h2><p>图片来自<a target="_blank" rel="external nofollow noopener noreferrer" href="/safego/?u=aHR0cHM6Ly9oYW93YWxscGFwZXIuY29tL2hvbWVWaWV3TG9vay8xNjQ0OTM4Nzg0OTU2NzYxNg">哲风壁纸</a></p><p><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/28/67e6470048c78.webp" alt="夕阳，玫瑰，冷寂，孤独"></p></article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>Hexo配置SWPP实现PWA</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="https://blog.liushen.fun/posts/4355f2b3/">https://blog.liushen.fun/posts/4355f2b3/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info" style="position:relative;z-index:3"><div class="post-copyright-a" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>作者</h><div class="post-copyright-cc-info"><h>LiuShen</h></div></div><div class="post-copyright-c" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>发布于</h><div class="post-copyright-cc-info"><h>2025-03-28</h></div></div><div class="post-copyright-u" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>更新于</h><div class="post-copyright-cc-info"><h>2025-03-28</h></div></div><div class="post-copyright-c" style="display:inline-block;width:fit-content;margin:20px 20px 20px 0"><h>许可协议</h><div class="post-copyright-cc-info"><a rel="noopener" target="_blank" title=" CC BY 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/?ref=chooser-v1">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E4%BC%98%E5%8C%96/">优化</a><a class="post-meta__tags" href="/tags/SWPP/">SWPP</a><a class="post-meta__tags" href="/tags/%E5%8D%9A%E5%AE%A2%E7%AE%A1%E7%90%86/">博客管理</a><a class="post-meta__tags" href="/tags/Service-Worker/">Service Worker</a></div><div class="post-share"><div class="social-share" data-image="https://p.liiiu.cn/i/2025/03/27/67e56a745e1cc.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i>来😍鼠标过来一点~</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/config/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="/config/img/wechat.png" alt="微信"></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/config/img/wechat.png" target="_blank"><img class="post-qr-code-img" src="" data-lazy-src="/config/img/wechat.png" alt="支付宝"></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><a class="prev-post pull-left" href="/posts/43f0ef13/" title="Cloudflare/Vercel项目推荐(4)"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/20/67dc1dbe66213.webp" onerror='onerror=null,src="/img/404.jpg"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Cloudflare/Vercel项目推荐(4)</div></div></a><a class="next-post pull-right" href="/posts/4bb33804/" title="PaddleYOLO训练自己的数据集"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/08/67f49876a62e5.webp" onerror='onerror=null,src="/img/404.jpg"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">PaddleYOLO训练自己的数据集</div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a href="/posts/caee2d9f/" title="美化你的RSS订阅地址"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/18/68024a618942b.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-18</div><div class="title">美化你的RSS订阅地址</div></div></a><a href="/posts/40702a0d/" title="本地实现HEXO文章AI摘要"><img class="cover" src="" data-lazy-src="https://p.liiiu.cn/i/2025/05/06/6819cd4532457.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2025-05-07</div><div class="title">本地实现HEXO文章AI摘要</div></div></a></div></div><hr class="custom-hr"><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="artalk-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info is-center"><div class="author-info-detail"><p class="author-info-hello">👋 欢迎光临！</p><p class="author-info-desc">你们好呀！我是站长LiuShen！一个快乐，积极，热爱生活的孩纸！😜😜😜</p></div><div class="avatar-img"><img class="mood-icon" src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/14/67d301461a24a.webp" alt="🤤" onerror='this.onerror=null,this.src="/img/friend_404.gif"'><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/03/13/67d2fc82d329c.webp" onerror='this.onerror=null,this.src="/img/friend_404.gif"' alt="avatar"></div><div class="author-info-name">LiuShen</div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">72</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">98</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/willow-god"><i class="fab fa-github"></i><span>Follow Me 🛫</span></a><div class="card-info-social-icons"><a class="social-icon" href="mailto:01@liushen.fun" target="_blank" title="Email"><i class="fa-solid fa-envelope"></i></a><a class="social-icon" href="http://wpa.qq.com/msgrd?v=3&amp;uin=3162475700&amp;site=qq&amp;menu=yes" target="_blank" title="QQ：3162475700"><i class="fa-brands fa-qq"></i></a><a class="social-icon" href="https://wakatime.com/@LiuShen" target="_blank" title="Wakatime"><i class="fa-solid fa-chart-column"></i></a><a class="social-icon" href="https://blog.liushen.fun/atom.xml" target="_blank" title="rss地址"><i class="fa-solid fa-rss"></i></a></div></div><div class="card-widget" id="card-poem"><div id="poem_sentence"></div><div id="poem_info"><div id="poem_dynasty"></div><div id="poem_author"></div></div></div><script src="/js/jinrishici.js" charset="utf-8"></script><script>jinrishici.load((function(e){var n=document.querySelector("#poem_sentence"),t=document.querySelector("#poem_author"),o=document.querySelector("#poem_dynasty"),r=e.data.content;r=r.substr(0,r.length-1),n.innerHTML=r,o.innerHTML=e.data.origin.dynasty,t.innerHTML=e.data.origin.author+"《"+e.data.origin.title+"》"}))</script><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><p><strong>博客架构概览：</strong><br>⚙️框架核心：Hexo<br>🕹️界面设计：Butterfly<br>🔮安全保障：长亭雷池<br>🔩管理工具：宝塔面板，1Panel<br>🎰服务器支持：阿里云，腾讯云<br>🎲CDN加速：多吉云，CloudFlare<br><strong>快捷跳转地址：</strong><br>🧩个人相册：<a target="_blank" rel="noopener" href="https://xc.liushen.fun">xc.liushen.fun</a><br>🤖个人导航：<a target="_blank" rel="noopener" href="https://www.liushen.fun">www.liushen.fun</a><br></p><img src="" data-lazy-src="/config/img/notice.gif" alt="可爱捏" title="可爱捏" style="width:100%;border-radius:10px"></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A2%8E%E7%A2%8E%E5%BF%B5"><span class="toc-text">碎碎念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D"><span class="toc-text">简单介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8E%9F%E7%94%9FSW"><span class="toc-text">原生SW</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#SWPP%E4%BC%98%E7%82%B9"><span class="toc-text">SWPP优点</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%80%E5%A7%8B%E9%85%8D%E7%BD%AE"><span class="toc-text">开始配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%92%E4%BB%B6%E5%AE%89%E8%A3%85"><span class="toc-text">插件安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE"><span class="toc-text">插件配置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#DOMAIN-HOST"><span class="toc-text">DOMAIN_HOST</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isStable"><span class="toc-text">isStable</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#referer"><span class="toc-text">referer</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#getStandbyRequests"><span class="toc-text">getStandbyRequests</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#matchCacheRule"><span class="toc-text">matchCacheRule</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E6%95%88%E6%9E%9C"><span class="toc-text">查看效果</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PWA%E5%AE%9E%E7%8E%B0"><span class="toc-text">PWA实现</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%B4%E9%83%A8%E4%BF%A1%E6%81%AF"><span class="toc-text">头部信息</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#manifest-json"><span class="toc-text">manifest.json</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-text">总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%AB%A0"><span class="toc-text">参考文章</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%AF%8F%E6%97%A5%E4%B8%80%E5%9B%BE"><span class="toc-text">每日一图</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/7915ee6b/" title="数据库可视化WEB工具对比"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/05/25/6832cc105bc41.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="数据库可视化WEB工具对比"></a><div class="content"><a class="title" href="/posts/7915ee6b/" title="数据库可视化WEB工具对比">数据库可视化WEB工具对比</a><time datetime="2025-05-25T10:01:21.000Z" title="更新于 2025-05-25 18:01:21">2025-05-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/40702a0d/" title="本地实现HEXO文章AI摘要"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/05/06/6819cd4532457.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="本地实现HEXO文章AI摘要"></a><div class="content"><a class="title" href="/posts/40702a0d/" title="本地实现HEXO文章AI摘要">本地实现HEXO文章AI摘要</a><time datetime="2025-05-06T16:01:21.000Z" title="更新于 2025-05-07 00:01:21">2025-05-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5f71a4b1/" title="耗子面板和DPanel简单体验"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/27/680dc7916ef34.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="耗子面板和DPanel简单体验"></a><div class="content"><a class="title" href="/posts/5f71a4b1/" title="耗子面板和DPanel简单体验">耗子面板和DPanel简单体验</a><time datetime="2025-04-28T14:48:21.000Z" title="更新于 2025-04-28 22:48:21">2025-04-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/caee2d9f/" title="美化你的RSS订阅地址"><img src="" data-lazy-src="https://p.liiiu.cn/i/2025/04/18/68024a618942b.webp" onerror='this.onerror=null,this.src="/img/404.jpg"' alt="美化你的RSS订阅地址"></a><div class="content"><a class="title" href="/posts/caee2d9f/" title="美化你的RSS订阅地址">美化你的RSS订阅地址</a><time datetime="2025-04-18T12:48:21.000Z" title="更新于 2025-04-18 20:48:21">2025-04-18</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap" style="background:0 0"><div id="footer_icons"><div><a class="icon_link" rel="noopener external nofollow" href="https://www.liushen.fun/" title="导航站点" target="_blank"><i class="fa-solid fa-compass"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://admin.qidian.qq.com/static_proxy/b2b-qq/wpa-link/index.html#/person?uin=3162475700" title="联系QQ" target="_blank"><i class="fa-brands fa-qq"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://github.com/willow-god" title="我的github主页" target="_blank"><i class="fa-brands fa-github"></i></a><a class="icon_link" rel="noopener external nofollow" href="mailto:01@liushen.fun" title="发送邮件至博主邮箱" target="_blank"><i class="fa-solid fa-envelope"></i></a></div><div class="footer_logo_container" onclick="btf.scrollToDest(0,500)" title="返回顶部"><img class="footer_logo" src="" data-lazy-src="/img/footer.gif"></div><div><a class="icon_link" rel="noopener external nofollow" href="https://wakatime.com/@LiuShen" title="Wikitime" target="_blank"><i class="fa-solid fa-clock"></i></a><a class="icon_link" rel="noopener external nofollow" href="https://gitlab.com/" title="gitlab" target="_blank"><i class="fa-brands fa-gitlab"></i></a><a class="icon_link" href="/shuoshuo/" title="日常说说" data-pjax-state="data-pjax-state"><i class="fa-solid fa-file-pen"></i></a><a class="icon_link" href="/comment/" title="留言板" data-pjax-state="data-pjax-state"><i class="fa-solid fa-comment"></i></a></div></div><div id="footer_content"><div class="footer-group"><h3 class="footer-title">关于本站</h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://www.liushen.fun/">导航站点</a><a class="footer-item" href="/shuoshuo/">日常说说</a><a class="footer-item" target="_blank" href="https://um.liushen.fun/share/bIEnQp0xnMxD8c9V/blog.liushen.fun">访客信息</a><a class="footer-item" target="_blank" href="https://mm.liushen.fun/">提笔摘星</a><a class="footer-item" target="_blank" href="https://status.liushen.fun/">在线状态</a><a class="footer-item" href="/subscribe/">订阅本站</a></div></div><div class="footer-group"><h3 class="footer-title">加入组织</h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://www.boyouquan.com/home">博友圈</a><a class="footer-item" target="_blank" href="https://github.com/timqian/chinese-independent-blogs">中博列表</a><a class="footer-item" target="_blank" href="https://blogwe.com/">博客我们</a><a class="footer-item" target="_blank" href="https://storeweb.cn/">个性商店</a><a class="footer-item" target="_blank" href="https://bf.zzxworld.com/">发现博客</a><a class="footer-item" target="_blank" href="https://ourblo.gs/">OurBlogs</a></div></div><div class="footer-group"><h3 class="footer-title">文章整理</h3><div class="footer-links"><a class="footer-item" href="/categories/website/">博客管理</a><a class="footer-item" href="/categories/learning/">学习资料</a><a class="footer-item" href="/categories/daily-share/">日常分享</a><a class="footer-item" href="/archives/">时光卷轴</a><a class="footer-item" href="/charts/">文章通览</a><a class="footer-item" href="/categories/">查看全部</a></div></div><div class="footer-group"><h3 class="footer-title">文章标签</h3><div class="footer-links"><a class="footer-item" href="/tags/JavaScript/">JS知识</a><a class="footer-item" href="/tags/Hexo/">本站框架</a><a class="footer-item" href="/tags/机器学习/">机器学习</a><a class="footer-item" href="/tags/日记/">个人日记</a><a class="footer-item" href="/tags/CSS/">CSS知识</a><a class="footer-item" href="/tags/">查看全部</a></div></div><div class="footer-group"><h3 class="footer-title">自建工具</h3><div class="footer-links"><a class="footer-item" target="_blank" rel="noopener" href="https://chat.liushen.fun/">清羽AI</a><a class="footer-item" target="_blank" rel="noopener" href="https://hot.liushen.fun/">今日热榜</a><a class="footer-item" target="_blank" rel="noopener" href="https://cover.qyliu.top/">封面设计</a><a class="footer-item" target="_blank" rel="noopener" href="https://icon.qyliu.top/">万变图标</a><a class="footer-item" target="_blank" rel="noopener" href="https://tmail.qyliu.top/">临时邮箱</a><a class="footer-item" target="_blank" rel="noopener" href="https://share.liushen.fun/">内容中转</a></div></div><div class="footer-group" id="friend-links-in-footer"><h3 class="footer-title">友链<button title="换一批" href="javascript:;" onclick="liushen.randomLink()"><i class="fa-solid fa-rotate-right"></i></button></h3><div class="footer-links"><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试1</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试2</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试3</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试4</a><a class="footer-item" target="_blank" href="https://blog.liushen.fun">测试5</a><a class="footer-item" href="/link/" data-pjax-state="data-pjax-state">查看更多</a></div></div></div><div id="footer-bottom"><div class="footer-bottom-content"><div class="footer-bottom-left"><span class="copyright">©2021 - 2025 By <a target="_blank" rel="noopener" href="https://blog.liushen.fun/about/" title="点击访问&quot;LiuShen&quot;的主页" style="margin-left:5px">LiuShen</a></span><div><a class="footer-bottom-link" target="_blank" href="https://beian.miit.gov.cn/" rel="noopener external nofollow" title="工信部备案号">陕ICP备2024028531号-2</a><a class="footer-bottom-link" target="_blank" href="https://beian.mps.gov.cn/#/query/webSearch?code=61011602000637" rel="noopener external nofollow" title="公安备案号">陕公网安备61011602000637号</a></div></div><div class="footer-bottom-right"><div id="runtime" title="本站运行时间">本站已苟活：0 天 0 时 0 分 0 秒</div><div><a class="footer-bottom-link" target="_blank" href="https://www.dogecloud.com/?iuid=9173" rel="noopener external nofollow" title="本站通过多吉云CDN提供站点加速">多吉云CDN</a><a class="footer-bottom-link" target="_blank" href="https://hexo.io/zh-cn/" rel="noopener external nofollow" title="本站使用Hexo架构搭建而成">Hexo静态框架</a><a class="footer-bottom-link" target="_blank" href="https://butterfly.js.org/" rel="noopener external nofollow" title="本站主题由Butterfly主题魔改而成">LiuShen主题</a></div></div></div></div></div><script>window.liushen||(window.liushen={saveData:(e,n)=>{localStorage.setItem(e,JSON.stringify({time:Date.now(),data:n}))},loadData:(e,n)=>{let t=JSON.parse(localStorage.getItem(e));if(t){let e=Date.now()-t.time;if(e>=0&&e<6e4*n)return t.data}return null},runtime:()=>{const e=e=>e>9?e:"0"+e,n=new Date("2021/12/12 01:27:36").getTime(),t=Date.now();let i=Math.round((t-n)/1e3),o="本站已苟活：";i>=86400&&(o+=`${e(Math.floor(i/86400))} 天 `,i%=86400),i>=3600&&(o+=`${e(Math.floor(i/3600))} 时 `,i%=3600),i>=60&&(o+=`${e(Math.floor(i/60))} 分 `,i%=60),o+=`${e(i)} 秒`;const l=document.getElementById("runtime");l&&(l.innerHTML=o),setTimeout(window.liushen.runtime,1e3)},randomLink:()=>{let e=window.liushen.loadData("links",30);if(e){let n=document.querySelectorAll("#friend-links-in-footer .footer-item");if(!n.length)return;for(let t=0;t<n.length;t++){let i=Math.floor(Math.random()*e.length);n[t].innerText=e[i].name,n[t].href=e[i].link,e.splice(i,1)}}else fetch("/flink_count.json").then((e=>e.json())).then((e=>{window.liushen.saveData("links",e.link_list),window.liushen.randomLink()}))}}),window.liushen.randomLink(),document.addEventListener("DOMContentLoaded",window.liushen.randomLink),window.liushen.runtime()</script></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="translateLink" type="button" title="简繁转换" style="width:35px">繁</button><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i><span class="rightside-text">阅读模式</span></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fa-regular fa-star-half-stroke"></i><span class="rightside-text">亮暗切换</span></button><button id="cat" onclick="toggleLive2dVisibility()" title="小猫显隐"><i class="fa-solid fa-cat"></i><span class="rightside-text">小猫显隐</span></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fa-solid fa-arrows-left-right-to-line"></i><span class="rightside-text">侧栏显隐</span></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i><span class="rightside-text">更多设置</span></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i><span class="rightside-text">显示目录</span></button><button id="fullscreen" onclick="toggleFullScreen()" title="全屏切换"><i class="fa-solid fa-expand"></i><span class="rightside-text">全屏切换</span></button><a id="to_comment" href="#post-comment" title="前往评论"><i class="fas fa-comments"></i><span class="rightside-text">快速评论</span></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i><span class="rightside-text">回到顶部</span></button></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="fa-solid fa-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="fa-solid fa-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="fa-solid fa-arrow-rotate-right"></i></div><div class="rightMenu-item" id="menu-home"><i class="fa-solid fa-house"></i></div></div><div class="rightMenu-group rightMenu-line hide" id="menu-text"><a class="rightMenu-item" id="copy" href="javascript:rm.copySelect();"><i class="fa-solid fa-copy"></i><span>复制选中文字</span></a><a class="rightMenu-item" id="reply" href="javascript:rm.replySelect();"><i class="fa-regular fa-comment"></i><span>评论选中段落</span></a></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" href="/archives/"><i class="fa-solid fa-archive"></i><span>文章时间线</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="fa-solid fa-folder-open"></i><span>文章分大类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="fa-solid fa-tags"></i><span>文章小标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuNormal"><a class="rightMenu-item menu-link" id="menu-radompage" href="/comment/"><i class="fa-solid fa-shoe-prints"></i><span>随心留言板</span></a><div class="rightMenu-item" id="menu-translate"><i class="fa-solid fa-earth-asia"></i><span>繁简模式切换</span></div><div class="rightMenu-item" id="menu-live2dvisibility"><i class="fa-solid fa-cat"></i><span>小猫显示隐藏</span></div><div class="rightMenu-item" id="menu-print"><i class="fa-solid fa-print fa-fw"></i><span>打印整个页面</span></div><a class="rightMenu-item menu-link" id="statement" href="/statement/"><i class="fa-regular fa-copyright fa-fw"></i><span>网站声明</span></a></div></div><div id="rightmenu-mask"></div><div><script src="/js/others.js?v=5.0.0"></script><script src="/js/utils.js?v=5.0.0"></script><script src="/js/main.js?v=5.0.0"></script><script src="https://jsd.liiiu.cn/npm/echarts@5.5.1/dist/echarts.simple.min.js"></script><script src="/js/rightmenu.js?v=5.0.0"></script><script src="/js/jinrishici.js"></script><script src="/js/tw_cn.js?v=5.0.0"></script><script src="https://jsd.liiiu.cn/npm/@fancyapps/ui@5.0.36/dist/fancybox/fancybox.umd.min.js"></script><script src="https://jsd.liiiu.cn/npm/instant.page@5.2.0/instantpage.min.js" type="module"></script><script src="https://jsd.liiiu.cn/npm/vanilla-lazyload@19.1.3/dist/lazyload.iife.min.js"></script><div class="js-pjax"><script>(()=>{let t=null;const e=null,o="shuoshuo"===GLOBAL_CONFIG_SITE.pageType,a=()=>{t&&(t.destroy(),t=null)},n=e=>t&&t.setDarkMode("dark"===e),l=(l=document,i=location.pathname)=>{t=Artalk.init({el:l.querySelector("#artalk-wrap"),server:"https://atk.liushen.fun",site:"清羽飞扬",darkMode:"dark"===document.documentElement.getAttribute("data-theme"),...e,pageKey:i,imgUploader:function(t){let e="Bearer 28|q18njD3pLtHiFy9WidqQrREwqZzb8Zionr8WzilI",o="https://www.baiwulin.work/api/v1/upload",a=new Headers;a.set("Accept","application/json"),a.set("Authorization",e);let n=new FormData;n.append("file",t);const l=(t,e,o)=>fetch(t,{method:"POST",body:e,headers:o}).then((t=>t.json())).then((t=>t.data.links.url)).catch((t=>(console.error("Image upload failed:",t),null)));return l(o,n,a).then((t=>t||(console.warn("雾林图床接口失败，尝试替换为秋叶图床"),e="Bearer 11|lsReISlSS0dyhDzt35ovtfYefGbWSRW2vvntPXs7",o="https://imgse.koxiuqiu.cc/api/v1/upload",a.set("Authorization",e),l(o,n,a))))}}),"null"!==GLOBAL_CONFIG.lightbox&&(t.on("list-loaded",(()=>{t.ctx.get("list").getCommentNodes().forEach((t=>{const e=t.getRender().$content;btf.loadLightbox(e.querySelectorAll("img:not([atk-emoticon])"))}))})),o&&(window.shuoshuoComment.destroyArtalk=()=>{a(),l.children.length&&(l.innerHTML="",l.classList.add("no-comment"))}),btf.addGlobalFn("pjaxSendOnce",a,"destroyArtalk"),btf.addGlobalFn("themeChange",n,"artalk"))},i=async(t,e)=>{"object"==typeof Artalk||(await btf.getCSS("https://jsd.liiiu.cn/npm/artalk@2.9.1/dist/Artalk.min.css"),await btf.getScript("https://jsd.liiiu.cn/npm/artalk@2.9.1/dist/Artalk.min.js")),l(t,e)};o?window.shuoshuoComment={loadComment:i}:setTimeout(i,0)})()</script></div><script>window.newestComments={changeContent:e=>(""===e||(e=(e=(e=(e=(e=e.replace(/<img.*?src="(.*?)"?[^\>]+>/gi,"[图片]")).replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,"[链接]")).replace(/<pre><code>.*?<\/pre>/gi,"[代码]")).replace(/<code>.*?<\/code>/gi,"[代码]")).replace(/<[^>]+>/g,"")).length>150&&(e=e.substring(0,150)+"..."),e),generateHtml:(e,t)=>{let n="";if(e.length)for(let t=0;t<e.length;t++){if(n+='<div class="aside-list-item">',e[t].avatar){const a="data-lazy-src";n+=`<a href="${e[t].url}" class="thumbnail"><img ${a}="${e[t].avatar}" alt="${e[t].nick}"></a>`}n+=`<div class="content">\n        <a class="comment" href="${e[t].url}" title="${e[t].content}">${e[t].content}</a>\n        <div class="name"><span>${e[t].nick} / </span><time datetime="${e[t].date}">${btf.diffDate(e[t].date,!0)}</time></div>\n        </div></div>`}else n+="暂无评论";t.innerHTML=n,window.lazyLoadInstance&&window.lazyLoadInstance.update(),window.pjax&&window.pjax.refresh(t)},newestCommentInit:(e,t)=>{const n=document.querySelector("#card-newest-comments .aside-list");if(n){const a=btf.saveToLocal.get(e);a?newestComments.generateHtml(JSON.parse(a),n):t(n)}},run:(e,t)=>{newestComments.newestCommentInit(e,t),btf.addGlobalFn("pjaxComplete",(()=>newestComments.newestCommentInit(e,t)),e)}}</script><script>window.addEventListener("load",(()=>{const t="artalk-newest-comments",{changeContent:a,generateHtml:e,run:n}=window.newestComments,r=new URLSearchParams({site_name:"清羽飞扬",limit:"5"});n(t,(async n=>{try{const s=await fetch(`https://atk.liushen.fun/api/v2/stats/latest_comments?${r}`),o=await s.json(),{avatarCdn:c,avatarDefault:i}=await(async()=>{const t=t=>t.startsWith("d=")?t:`d=${t}`;try{const a=await fetch("https://atk.liushen.fun/api/v2/conf"),e=await a.json(),{mirror:n,params:r,default:s}=e.frontend_conf.gravatar;return{avatarCdn:n,avatarDefault:t(r||s)}}catch(a){return console.error(a),{avatarCdn:"",avatarDefault:t("")}}})(),l=o.data.map((t=>({avatar:c&&t.email_encrypted?`${c}${t.email_encrypted}?${i}`:"",content:a(t.content_marked),nick:t.nick,url:t.page_url,date:t.date})));btf.saveToLocal.set(t,JSON.stringify(l),10/1440),e(l,n)}catch(t){console.log(t),n.textContent="无法获取评论，请确认相关配置是否正确"}}))}))</script><script src="/config/memos/memos.js"></script><script id="canvas_nest" defer color="128,128,128" opacity="0.7" zindex="-1" count="99" mobile="false" src="https://jsd.liiiu.cn/npm/butterfly-extsrc@1.1.4/dist/canvas-nest.min.js"></script><link rel="stylesheet" href="https://jsd.liiiu.cn/npm/aplayer@1.10.1/dist/APlayer.min.css" media="print" onload='this.media="all"'><script src="https://jsd.liiiu.cn/npm/aplayer@1.10.1/dist/APlayer.min.js"></script><script src="https://jsd.liiiu.cn/npm/meting@2.0.1/dist/Meting.min.js"></script><script src="https://jsd.liiiu.cn/npm/pjax@0.2.8/pjax.min.js"></script><script>(()=>{window.pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"],cacheBust:!1,analytics:!1,scrollRestoration:!1});const e=e=>{e&&Object.values(e).forEach((e=>e()))};document.addEventListener("pjax:send",(()=>{btf.removeGlobalFnEvent("pjaxSendOnce"),btf.removeGlobalFnEvent("themeChange");const t=document.body.classList;t.contains("read-mode")&&t.remove("read-mode"),e(window.globalFn.pjaxSend)})),document.addEventListener("pjax:complete",(()=>{btf.removeGlobalFnEvent("pjaxCompleteOnce"),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),n=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(n)),e.parentNode.replaceChild(t,e)})),e(window.globalFn.pjaxComplete)})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404")}))})()</script><script async data-pjax="" src="/config/busuanzi/busuanzi.js"></script><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div><script src="https://jsd.liiiu.cn/npm/algoliasearch@5.8.1/dist/lite/builds/browser.umd.min.js"></script><script src="https://jsd.liiiu.cn/npm/instantsearch.js@4.75.0/dist/instantsearch.production.min.js"></script><script src="/js/search/algolia.js?v=5.0.0"></script></div></div><div class="needEndHide" id="nav-music"><div id="nav-music-hoverTips" onclick="liuMusic.musicToggle()">音乐已暂停</div><meting-js id="13597135963" server="netease" type="playlist" mutex="true" preload="none" data-lrctype="0" order="random" volume="0.8" api="https://met.liiiu.cn/meting/api?server=:server&amp;type=:type&amp;id=:id&amp;r=:r"></meting-js></div><script data-pjax="">function butterfly_swiper_injector_config(){var a=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),a.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/08/67f49876a62e5.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt="">PaddleYOLO训练自己的数据集</a><div class="blog-slider__text">近期一直在研究毕业设计，在其中，我涉及到了PaddleYOLO的训练和部署，在网上的教程较少，经过不断努力，我也算是跑出来了，所以在这里分享出来做个记录，防止下次使用又忘记了怎么搞。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/4bb33804/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/27/680dc7916ef34.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt="">耗子面板和DPanel简单体验</a><div class="blog-slider__text">最近毕业设计临近尾声，代码也敲完了，目前就剩稍微的调优，就可以开始写论文啦！在闲暇时间，我也尝试部署了一些不一样的面板程序，总感觉1panel稍微有些复杂，很多功能并用不上，比如GPU，下面简单分享一下我的体验。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/5f71a4b1/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/05/06/6819cd4532457.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-05-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt="">本地实现HEXO文章AI摘要</a><div class="blog-slider__text">五一假期结束啦！这五天啥也没干，就在宿舍敲代码，都快无聊死了，恰逢找到了一些免费API，就自己实现一个AI摘要吧！利用API生成摘要文本放在文章头部，再通过hexo进行渲染就好啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/40702a0d/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/05/25/6832cc105bc41.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-05-25</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt="">数据库可视化WEB工具对比</a><div class="blog-slider__text">最近迁移服务器，并且搞了一个1P专业版玩玩，感觉效果很不错，想找一个管理数据库的服务，其中看了phpmyadmin等一些知名项目，但是都不太符合我的要求，最后经过筛选，找到了比较合适的，分享给大家！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/7915ee6b/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src= "" data-lazy-src="https://p.liiiu.cn/i/2025/04/18/68024a618942b.webp" alt="" onerror="this.src=/img/error-page.png; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2025-04-18</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt="">美化你的RSS订阅地址</a><div class="blog-slider__text">近期天天忙着毕业设计，冷落了站点文章的更新，最近也终于算是快要搞完了，于是开始捣鼓一些好玩的东西，在浏览阮一峰大佬的周刊时，了解到了RSS也能美化，折腾了一下，没想到还真实现了，在此分享一下。</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/caee2d9f/&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="/",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://jsd.liiiu.cn/npm/swiper@11.1.14/swiper-bundle.min.js"></script><script defer data-pjax="" src="/config/swiper/swiper_init.js"></script><script src="https://jsd.liiiu.cn/npm/live2d-widget@^3.1.3/lib/L2Dwidget.min.js"></script><script>L2Dwidget.init({pluginModelPath:"assets/",model:{scale:1,hHeadPos:.5,vHeadPos:.618,jsonPath:"/live2dw/assets/tororo.model.json"},display:{superSample:2,width:250,height:500,position:"left",hOffset:-20,vOffset:-90},mobile:{show:!1,scale:.5},react:{opacityDefault:.7,opacityOnHover:.2},log:!1,pluginJsPath:"lib/",pluginRootPath:"live2dw/",tagMode:!1})</script></body></html>